﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.SessionState;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS.Module
{
    public partial class ucGioHangDetail : System.Web.UI.UserControl
    {
        ShopingCart vpp = new ShopingCart();
        HttpSessionState ss = HttpContext.Current.Session;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                load();
            }
        }

        public void load()
        {
            HttpSessionState ss = HttpContext.Current.Session;
            string session = ss.SessionID;
            DataTable tb = new DataTable();
            if (Session["GioHang"] != null)
            {
                vpp.setTable((DataTable)Session["GioHang"]);
                tb = vpp.getTable();
                tb = (DataTable)Session["GioHang"];
                if (tb.Rows.Count == 0)
                {
                    lblSum.Text = "0 đ";
                    lblAmount.Text = "0";
                }
                else
                {
                    float tong = 0;
                    float sum = 0;
                    foreach (DataRow dr in tb.Rows)
                    {
                        tong += float.Parse(dr[3].ToString());
                        sum += float.Parse(dr[4].ToString());
                    }
                    if (Session["lang"].ToString() == "VN")
                    {
                        lblSum.Text = String.Format("{0:0,0 đ}", tong);
                        lblAmount.Text = tb.Rows.Count.ToString();
                    }
                    else
                    {
                        lblSum.Text = String.Format("{0:0,0 $}", sum);
                        lblAmount.Text = tb.Rows.Count.ToString();
                    }
                }
            }
            else
            {
                lblSum.Text = "0 đ";
                lblAmount.Text = "0";
            }
        }

        public string soluong()
        {
            HttpSessionState ss = HttpContext.Current.Session;
            string session = ss.SessionID;
            DataTable dt = new cmsGioHangBL().SelectBySessionChuaXL(session);
            if (dt.Rows.Count == 0)
                return "0";
            else
                return dt.Rows.Count.ToString();
        }

        public string TongTien()
        {

            int tong = 0;
            int sum = 0;
            string session = ss.SessionID;
            DataTable dt = new cmsGioHangBL().SelectBySessionChuaXL(session);
            if (dt.Rows.Count == 0)
                return "0";
            else
            {
                foreach (DataRow dr in dt.Rows)
                {
                    tong += int.Parse(dr["ThanhTien"].ToString());
                    sum += int.Parse(dr["TotalMoney"].ToString());

                }
                if (Session["lang"].ToString() == "VN")
                {
                    return tong.ToString();
                }
                else return sum.ToString();

            }
        }

        protected void btn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("/GioHang.aspx");
        }
    }
}